<!DOCTYPE html>
<html>

<head>
    <title>闲瓜市场 - 添加商品</title>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
    <link rel="stylesheet" type="text/css" href="{{url_for('static',filename='templates/upload.css')}}" />
    <script src="{{url_for('static',filename='js/upload.js')}}"></script>
    <script src="{{url_for('static',filename='js/global.js')}}"></script>
</head>

<body onload="onLoad()">
    <nav class="nav">
        <div class="navHerf" id="toFrontPage"><a href="/">首页</a></div>
        <div class="navHerf" id="toLoginPage"><a href="/login">登录</a></div>
        <div class="navHerf" id="toRegPage"><a href="/register">注册</a></div>
        <div class="navHerf" id="toUploadPage"><a href="/upload_new">添加商品</a></div>
        <div class="navUser" id="curUser"><a href="/myinfo">未登录</a></div>
    </nav>

    <div id="title">
        {% if origin == None %}
        <h1>填写商品信息</h1>
        {% else %}
        <h1>更新商品信息</h1>
        {% endif %}
    </div>
    
    <div id="preImg">
        {% if origin == None %}
        <img id="preview" src="" style="display: none;">
        {% else %}
        <img id="preview" src="{{origin['img_src']}}">
        {% endif %}
    </div>
    {% if origin != None %}
    <div class="Content-Main">
        <form method="post" id="form-goodsInfo" enctype="multipart/form-data">            
            <div class="itemInput">
                <span class="hint">商品名称：</span><input class="textInput" type="text" name="name" placeholder="商品名称" value="{{origin['name']}}">
            </div>
            <div class="itemInput">
                <span class="hint">价格：</span><input class="textInput" type="number" name="price" placeholder="价格" step="0.01" value="{{origin['price']}}">
            </div>
            <div class="itemInput">
                <span class="hint">描述：</span><input class="textInput" type="text" name="des" placeholder="描述" value="{{origin['des']}}">
            </div>
            <div class="itemInput">
                <span class="hint">上传图片：</span><input id="fileInUp" class="fileInput" type="file" name="img" onchange="setPreview(0)">
            </div>
            <div class="submit">
                <input type="button" class="submitButton" value="提交" onclick="checkAndSubmit('{{origin['gid']}}')">
                <input type="button" class="submitButton" value="取消" onclick="cancelEdit()">
            </div>
        </form>
    </div>
    {% else %}
    <div class="Content-Main">
        <form method="post" id="form-goodsInfo" enctype="multipart/form-data">
            <div class="itemInput">
                <span class="hint">商品名称：</span><input class="textInput" type="text" name="name" placeholder="商品名称">
            </div>
            <div class="itemInput">
                <span class="hint">价格：</span><input class="textInput" type="number" name="price" placeholder="价格" step="0.01">
            </div>
            <div class="itemInput">
                <span class="hint">描述：</span><input class="textInput" type="text" name="des" placeholder="描述">
            </div>
            <div class="itemInput">
                <span class="hint">上传图片：</span><input id="fileInNew" class="fileInput" type="file" name="img" onchange="setPreview(1)">
            </div>
            <div class="submit">
                <input type="button" class="submitButton" value="提交" onclick="checkAndSubmit('-1')">
            </div>
        </form>
    </div>
    {% endif %}
</body>

</html>